package com.tjsinfo.tjsoa.vote.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.vote.bo.ITVoteOpinionBoxBO;
import com.tjsinfo.tjsoa.vote.vo.TVoteOpinionBox;

public class OpinionBoxAddAction extends Action {
	private ITVoteOpinionBoxBO opinionBoxBo;
	public void setOpinionBoxBo(ITVoteOpinionBoxBO opinionBoxBo) {
		this.opinionBoxBo = opinionBoxBo;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {	
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Date date = new Date();
			Integer userId = ToolKit.getSessionUser(request).getUser_id();
			String userName = ToolKit.getSessionUser(request).getUsername();			
			String title = request.getParameter("title");
			String contact = request.getParameter("contact");
			Integer anonymity = Integer.parseInt(request.getParameter("anonymity"));
			
			TVoteOpinionBox tvob = new TVoteOpinionBox();
			tvob.setUserId(userId.toString());
			tvob.setUserName(userName);
			//tvob.setDeptId(deptId);
			//tvob.setDeptName(deptName);		
			
			tvob.setDateTime(sdf.parse(sdf.format(date)));
			tvob.setStatus(0);
			tvob.setTitle(title);
			tvob.setContact(contact);
			tvob.setAnonymity(anonymity);
			
			opinionBoxBo.save(tvob);
			
			request.setAttribute("linkurl", "vote/opinionBox/opinionBoxSelfList.jsp");
			request.setAttribute("message", "vote.opinionBoxAdd.message");
			
			return mapping.findForward("success");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failed");
		}
	}
}